package com.pipayshop.config;

import jakarta.servlet.Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * Web配置类，用于注册Spring。
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {


    // 创建一个DelegatingFilterProxy实例，并设置其目标bean名称为springSecurityFilterChain，用于代理Spring Security过滤器链。
    @Bean
    public DelegatingFilterProxy springSecurityFilter() {
        DelegatingFilterProxy filter = new DelegatingFilterProxy();
        // 设置目标过滤器的名字（通常是 security 配置中的名字）
        filter.setTargetBeanName("springSecurityFilterChain");
        return filter;
    }

    // 不校验

    // 注册上述创建的过滤器，并设置其启用状态为true，同时将其应用到所有URL模式下，确保所有请求都经过Spring Security过滤处理。
    @Bean
    public FilterRegistrationBean<DelegatingFilterProxy> springSecurityFilterRegistration(
            DelegatingFilterProxy springSecurityFilter) {
        FilterRegistrationBean<DelegatingFilterProxy> registration = new FilterRegistrationBean<>(springSecurityFilter);
        registration.setEnabled(true);
        registration.addUrlPatterns("/*");
        return registration;
    }


}
